package io.renren.modules.generator.controller;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.controller.BaseController;
import io.renren.modules.generator.entity.EnterpriseServiceArchiveEntity;
import io.renren.modules.generator.service.EnterpriseServiceArchiveService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;


/**
 * 企业服务档案
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2020-09-20 16:01:39
 */
@RestController
@RequestMapping("generator/enterpriseservicearchive")
@Api("企业服务档案接口")
public class EnterpriseServiceArchiveController extends BaseController {

    @Autowired
    private EnterpriseServiceArchiveService enterpriseServiceArchiveService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @ApiOperation("分页列表")
    public R page(@RequestParam(required = false) Map<String, Object> params){
        //if (enterpriseServiceArchiveEntity == null) {
        //    enterpriseServiceArchiveEntity = new EnterpriseServiceArchiveEntity();
        //}
        //enterpriseServiceArchiveEntity.setDeptId(getDeptId());
        PageUtils page = enterpriseServiceArchiveService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @ApiOperation("根据id获取实体")
    public R info(@PathVariable("id") Integer id){
		EnterpriseServiceArchiveEntity enterpriseServiceArchive = enterpriseServiceArchiveService.getById(id);

        return R.ok().put("enterpriseServiceArchive", enterpriseServiceArchive);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @ApiOperation("保存")
    public R save(@RequestBody EnterpriseServiceArchiveEntity enterpriseServiceArchive){
        enterpriseServiceArchive.setCreateBy(getUserNo());
        enterpriseServiceArchive.setCreateTime(new Date());
        enterpriseServiceArchive.setCreateByName(getUserName());
		enterpriseServiceArchiveService.save(enterpriseServiceArchive);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @ApiOperation("更新")
    public R update(@RequestBody EnterpriseServiceArchiveEntity enterpriseServiceArchive){
        enterpriseServiceArchive.setUpdateBy(getUserNo());
        enterpriseServiceArchive.setUpdateTime(new Date());
        enterpriseServiceArchive.setUpdateByName(getUserName());
		enterpriseServiceArchiveService.updateById(enterpriseServiceArchive);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @ApiOperation("删除")
    public R delete(@RequestBody Integer[] ids){
		enterpriseServiceArchiveService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
